package com.thinkpadteam.edugra;

import com.thinkpadteam.edugra.R;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.support.v4.widget.DrawerLayout;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.View.OnLongClickListener;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.RelativeLayout;
import android.widget.Toast;

public class MainActivity extends Activity {
//	private String[] LIST_NAV;
//	private ListView list_view;
//	private DrawerLayout list_layout;
	
	private ImageView btn_belajar, btn_bermain;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.main_activity);
		RelativeLayout mainact = (RelativeLayout) findViewById(R.id.mainact);
		mainact.setBackgroundResource(R.drawable.bg_home);
		
		/*ketika layar di tab maka akan ke halaman baru dengan layout main_lesson_activity.xml */
//		mainact.setOnClickListener(new OnClickListener() {
//			@Override
//			public void onClick(View v) {
//				openLesson();	
//			}
//		});
		
		/* mengaktifkan longClickable*/		
		mainact.setLongClickable(true);
		/* ketika di klik lama maka muncul creditnya*/
		mainact.setOnLongClickListener(new OnLongClickListener() {			
			@Override
			public boolean onLongClick(View v) {
				Toast.makeText(MainActivity.this, "Created by Team Thinkpad : \n Desy Kusuma Wardani \n Petrisia Meiga Natalia \n Valeria Neva Novea", Toast.LENGTH_LONG).show();
				return true;
			}
		});
		
		btn_belajar = (ImageView)findViewById(R.id.btn_belajar);
		btn_bermain = (ImageView)findViewById(R.id.btn_bermain);
		btn_belajar.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				openLesson();
			}
		});
		btn_bermain.setOnClickListener(new OnClickListener() {
			
			@Override
			public void onClick(View v) {
				openGame();
			}
		});		
		
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	
/* untuk membuka halaman dengan memanggil class MainLessonActivity */	
	public void openLesson(){
		Intent s = new Intent(this, MainLesson.class);
		startActivity(s);		
	}
	public void openGame(){
		Intent s = new Intent(this, MainGameActivity.class);
		startActivity(s);		
	}
	
	int backButtonCount = 0;
	public void onBackPressed()
	{
	    if(backButtonCount >= 1)
	    {
	        Intent intent = new Intent(Intent.ACTION_MAIN);
	        intent.addCategory(Intent.CATEGORY_HOME);
	        intent.setFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
	        startActivity(intent);
	    }
	    else
	    {
	        Toast.makeText(this, "Press the back button once again to close the application.", Toast.LENGTH_SHORT).show();
	        backButtonCount++;
	    }
	}
}
